package com.buddy.sds.scheduler.config;

import com.buddy.sds.scheduler.service.ISystemScheduleService;
import lombok.extern.slf4j.Slf4j;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;
@Slf4j
@Configuration
public class SchedulerConfig {

    @Autowired
    private ISystemScheduleService scheduleService;

    @Autowired
    public void init(Scheduler scheduler){

        if(scheduler != null){

            try {
                log.info(scheduler.getSchedulerName());
                log.info("调度器创建完成");


                log.info("开始恢复调度任务");

                scheduleService.restoreStatusFromDB();

                log.info("调度任务恢复完成");

                scheduler.start();

                log.info("调度器已启动");

            } catch (SchedulerException e) {
                //e.printStackTrace();
                log.error(e.getLocalizedMessage());
            }
        }


    }

}
